home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / kaffe / code.c < prev    next >
C/C++ Source or Header  |  1996-02-13  |  2KB  |  63 lines

  1. /*
  2.  * code.c
  3.  * Process a new code attribute.
  4.  *
  5.  * Copyright (c) 1996 Systems Architecture Research Centre,
  6.  *           City University, London, UK.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <assert.h>
  16. #include "gtypes.h"
  17. #include "file.h"
  18. #include "errors.h"
  19. #include "bytecode.h"
  20. #include "code.h"
  21. #include "classMethod.h"
  22.  
  23. void
  24. addCode(methods* m, uint32 len, classFile* fp)
  25. {
  26.     Code c;
  27.     int i;
  28.     u2 i2;
  29.  
  30.     readu2(&c.max_stack, fp);
  31.     readu2(&c.max_locals, fp);
  32.     readu4(&c.code_length, fp);
  33.     c.code = (u1*)malloc(c.code_length);
  34.     if (c.code == 0) {
  35.         throwException(OutOfMemoryError);
  36.     }
  37.     readm(c.code, c.code_length, sizeof(bytecode), fp);
  38.     readu2(&c.exception_table_length, fp);
  39.     c.exception_table = (exception*)malloc(c.exception_table_length * sizeof(exception));
  40.     if (c.exception_table == 0) {
  41.         throwException(OutOfMemoryError);
  42.     }
  43.     for (i = 0; i < c.exception_table_length; i++) {
  44.         readu2(&i2, fp);
  45.         c.exception_table[i].start_pc = i2;
  46.         readu2(&i2, fp);
  47.         c.exception_table[i].end_pc = i2;
  48.         readu2(&i2, fp);
  49.         c.exception_table[i].handler_pc = i2;
  50.         readu2(&i2, fp);
  51.         if (i2 == 0) {
  52.             c.exception_table[i].catch_type = 0;
  53.         }
  54.         else {
  55.             assert(m->constants->tags[i2] == CONSTANT_Class);
  56.             c.exception_table[i].catch_type = (char*)m->constants->data[CLASS_NAME(i2, m->constants)];
  57.         }
  58.     }
  59.     addMethodCode(m, &c);
  60.  
  61.     readAttributes(fp, m->class, m);
  62. }
  63.